/**
 * Project: happyouting-web-user
 * 
 * File Created at 2009-10-20
 * $Id: AjaxUserCheck.java 102 2009-11-22 08:44:27Z worldmaomao $
 * 
 * Copyright 2008 Alibaba.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.alibaba.happyouting.web.user.module.screen;

import com.alibaba.biz.command.Command;
import com.alibaba.biz.command.CommandSupport;
import com.alibaba.biz.command.dispatcher.CommandDispatcher;
import com.alibaba.biz.command.result.Result;
import com.alibaba.common.lang.StringUtil;
import com.alibaba.happyouting.user.dal.dataobject.User;
import com.alibaba.happyouting.web.screen.NormalScreen;
import com.alibaba.service.template.TemplateContext;
import com.alibaba.turbine.module.screen.TemplateScreen;
import com.alibaba.turbine.service.rundata.RunData;
import com.alibaba.webx.WebxException;

/**
 * TODO Comment of AjaxUserCheck
 * @author xingyue.wangxy
 *
 */
public  class AjaxUserCheck extends NormalScreen {
    

    protected void execute(RunData rundata, TemplateContext context)throws WebxException {
        String result   = null;
        String username  = rundata.getRequest().getParameter("username");
        
        if (StringUtil.isEmpty(username)) {
            result = "empty";
            context.put("result", result);
            return;
        }

        Command command = new CommandSupport("userAo", "checkUserExists");
        User user = new User();
        user.setUsername(username);
        command.getParameters().put("user", user);
        CommandDispatcher commandDispatcher = this.getCommandDispatcher();
        
        Result aoResult = commandDispatcher.execute(command);
        if(aoResult.isSuccess()){
            result = "userExists";
        }
        else{
            result = "userNotExists";
        }
        
        context.put("result", result);
    }
}
